package org.checkboo.math;



public class Line{
	
	private Vector3f origin;
	private Vector3f direction;
	
	public Line(){
		this.origin = new Vector3f();
		this.direction = new Vector3f();
	}
	
	public Line(Vector3f origin, Vector3f direction){
		this.origin = origin;
		this.direction = direction;
	}

	public Vector3f getOrigin() {
		return origin;
	}

	public void setOrigin(Vector3f origin) {
		this.origin = origin;
	}

	public Vector3f getDirection() {
		return direction;
	}

	public void setDirection(Vector3f direction) {
		this.direction = direction;
	}
	
	public float distance(Vector3f point){
		Vector3f tmp = new Vector3f();
		Vector3f tmp2 = new Vector3f();
		
		point.subtractRes(this.origin, tmp);
		this.direction.multiplyRes(this.direction.dot(tmp), tmp2);
		this.origin.addRes(tmp2, tmp);
		tmp.subtractRes(point, tmp2);
		
		return tmp2.magnitude();
	}

}
